
$(()=>{
    //顶部的下拉菜单
    $(".nav_menu").find(".link-holder").on("mouseenter",_.debounce(function(){
        $(this).parents(".nav_menu").find(".menuaa").slideDown(100)
    },200))
    $(".nav_menu").find(".link-holder").on("mouseleave",function(){
        $(this).parents(".nav_menu").find(".menuaa").hide()
    })
    $('.goindex').on('click',function(){
        location.href ='index.html' 
    })
    //滚动
    $(window).on("scroll",function(){
        let topH = $(".top_box").height();
        let topH1= $(".main_c").height()+topH;
        let scrollTop =$(document).scrollTop();
        if(scrollTop>topH){
            $(".mian-headerbox").css("position","fixed")
            $(".mian-headerbox").css("top",0)
        }else{
            $(".mian-headerbox").css("position","static")
        }
        if(scrollTop>topH1){
            $(".h3-nav-list").addClass("fixed")
        }else{
            $(".h3-nav-list").removeClass("fixed")
        }
    })
    //回到顶部
    $(window).on("scroll",function(){
        let scrollTop = $(window).scrollTop();
        if(scrollTop>100){
            $(".backTop").show()
        }else{
            $(".backTop").hide();
        }
        
    })
    // 随机验证码
    function random_ma(){
        let str = "";
        for(let i=0;i<4;i++){
            if(Math.random()>0.5){
                str+=parseInt(Math.random()*10)
            }else if(Math.random()>0.5){
                str+=String.fromCharCode(parseInt(Math.random()*26)+97)
            }else{
                str+=String.fromCharCode(parseInt(Math.random()*26)+65)
            }
        }
        return str
    }
    $('.yanmain').next().on('click',function(){
        console.log(111);
       $(this).text(random_ma());
    })
    $('.yanmain').on("blur",function(){
        if($('.yanmain').next().text()!=$('.yanmain').val()){
            $('.tip').css('display','block')
        }else{
            $('.tip').css('display','none')
        }
    })
    //随机颜色
    function randcolor(){
        let strcolor='#'
        for(let i=0;i<6;i++){
            strcolor+=parseInt(Math.random()*6).toString(16)
        }
        return strcolor
    }
    $('.random-ma').html(random_ma()).css("color",randcolor())
    $('.backTop').on("click",function(){
        $('html,body').animate({scrollTop:0})
    })
    //表单验证
    $("form").on("submit", function () {
        if($('.yanmain').next().text()!=$('.yanmain').val()){
            return false
        }
        var index = layer.load(1, {
            shade: [0.1, '#fff'] //0.1透明度的白色背景
        });
        $("#login").prop("disabled", true)
        $.ajax({
            url: "/api/login",
            type: "post",
            data: $(this).serialize(),
            success(res) {
                layer.close(index);
                layer.msg(res.msg)
                $("#login").prop("disabled", false)
                if (res && res.code == 200) {
                    //把登录成功的用户信息保存到本地存储
                    localStorage.setItem("user", JSON.stringify(res.data));
                    location.href = 'index.html'

                }
            }
        })
        return false;
    })
})